package net.seehealth.healthpad.application.service;

import java.io.IOException;

import net.seehealth.healthpad.Constants;
import net.seehealth.healthpad.model.upload.BloodPressure;
import net.seehealth.healthpad.model.upload.Electrocardio;
import net.seehealth.healthpad.model.upload.FoodRecord;
import net.seehealth.healthpad.model.upload.SportRecord;
import net.seehealth.healthpad.model.upload.Weight;
import net.seehealth.healthpad.model.usermanage.UserInfo;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

public class UpLoadRemoteSerivice {
	/**
	 *  上传血压检测数据
	  * @description:TODO
	  * @param 
	  * @return 
	  * @throws Exception   
	  * @author TODO
	  * @date 2012-4-13 上午11:04:30
	 */
	public boolean uploadBloodPressure(BloodPressure bloodPressure) throws Exception {
		boolean bool = false;
		SoapObject request = new SoapObject(Constants.Common.UPLOADXMLTARGETNAMESPACE,Constants.Common.UPLOADXMLMETHOD);
		request.addProperty("bloodPressure", bloodPressure);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		HttpTransportSE jtse = new HttpTransportSE(Constants.Common.UPLOADXMLWSDL);
		try {
			jtse.call(null, envelope);
			SoapObject so =(SoapObject)envelope.bodyIn;
			bool = Boolean.valueOf(so.getProperty("return").toString());
			return bool;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	/**
	 *  上传体重检测数据
	  * @description:TODO
	  * @param 
	  * @return 
	  * @throws Exception   
	  * @author TODO
	  * @date 2012-4-13 上午11:04:30
	 */
	public boolean uploadWeight(Weight weight) throws Exception {
		boolean bool = false;
		SoapObject request = new SoapObject(Constants.Common.UPLOADXMLTARGETNAMESPACE,Constants.Common.UPLOADXMLMETHOD);
		request.addProperty("weight", weight);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		HttpTransportSE jtse = new HttpTransportSE(Constants.Common.UPLOADXMLWSDL);
		try {
			jtse.call(null, envelope);
			SoapObject so =(SoapObject)envelope.bodyIn;
			bool = Boolean.valueOf(so.getProperty("return").toString());
			return bool;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	/**
	 *  上传心电检测数据
	  * @description:TODO
	  * @param 
	  * @return 
	  * @throws Exception   
	  * @author TODO
	  * @date 2012-4-13 上午11:04:30
	 */
	public boolean uploadElectrocardio(Electrocardio electrocardio) throws Exception {
		boolean bool = false;
		SoapObject request = new SoapObject(Constants.Common.UPLOADXMLTARGETNAMESPACE,Constants.Common.UPLOADXMLMETHOD);
		request.addProperty("electrocardio", electrocardio);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		HttpTransportSE jtse = new HttpTransportSE(Constants.Common.UPLOADXMLWSDL);
		try {
			jtse.call(null, envelope);
			SoapObject so =(SoapObject)envelope.bodyIn;
			bool = Boolean.valueOf(so.getProperty("return").toString());
			return bool;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	/**
	 *  上传运动记录数据
	  * @description:TODO
	  * @param 
	  * @return 
	  * @throws Exception   
	  * @author TODO
	  * @date 2012-4-13 上午11:04:30
	 */
	public boolean uploadSportRecord(SportRecord sportRecord) throws Exception {
		boolean bool = false;
		SoapObject request = new SoapObject(Constants.Common.UPLOADXMLTARGETNAMESPACE,Constants.Common.UPLOADXMLMETHOD);
		request.addProperty("sportRecord", sportRecord);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		HttpTransportSE jtse = new HttpTransportSE(Constants.Common.UPLOADXMLWSDL);
		try {
			jtse.call(null, envelope);
			SoapObject so =(SoapObject)envelope.bodyIn;
			bool = Boolean.valueOf(so.getProperty("return").toString());
			return bool;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	/**
	 *  上传膳食记录数据
	  * @description:TODO
	  * @param 
	  * @return 
	  * @throws Exception   
	  * @author TODO
	  * @date 2012-4-13 上午11:04:30
	 */
	public boolean uploadFoodRecord(FoodRecord foodRecord) throws Exception {
		boolean bool = false;
		SoapObject request = new SoapObject(Constants.Common.UPLOADXMLTARGETNAMESPACE,Constants.Common.UPLOADXMLMETHOD);
		request.addProperty("foodRecord", foodRecord);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		HttpTransportSE jtse = new HttpTransportSE(Constants.Common.UPLOADXMLWSDL);
		try {
			jtse.call(null, envelope);
			SoapObject so =(SoapObject)envelope.bodyIn;
			bool = Boolean.valueOf(so.getProperty("return").toString());
			return bool;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	/**
	 * 远程修改用户信息
	  * @description:TODO
	  * @param 
	  * @return 
	  * @throws Exception   
	  * @author TODO
	  * @date 2012-4-13 上午11:03:55
	 */
	public boolean updateRemoteUserInfo(UserInfo userInfo) throws Exception{
		boolean bool = false;
		SoapObject request = new SoapObject(Constants.Common.UPLOADXMLTARGETNAMESPACE,Constants.Common.UPLOADXMLMETHOD);
		request.addProperty("userInfo", userInfo);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		HttpTransportSE jtse = new HttpTransportSE(Constants.Common.UPLOADXMLWSDL);
		try {
			jtse.call(null, envelope);
			SoapObject so =(SoapObject)envelope.bodyIn;
			bool = Boolean.valueOf(so.getProperty("return").toString());
			return bool;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
}
